cd dos2unix-7.4.4
sed -i 's/-DENABLE_NLS //g' Makefile
sed -i '/po\//d' Makefile
make -j4
make install bindir=/home/${USERNAME}/local/bin -k
export PATH=/home/${USERNAME}/local/bin:$PATH

cd /home/${USERNAME}/workspace
echo "安装gawk..."
if [ -d "gawk-5.2.2" ]; then
    echo "The gawk folder exists, skipping the download and decompression steps."
elif [ -e "gawk-5.2.2.tar.gz" ]; then
    echo "gawk-5.2.2 compressed file exists, start decompressing steps."
    tar xf gawk-5.2.2.tar.gz
else
    echo "need Gawk compressed file exists."
    wget https://obs-9be7.obs.cn-east-2.myhuaweicloud.com/resource/gitcode/gawk-5.2.2.tar.gz
    tar xf gawk-5.2.2.tar.gz
fi
cd gawk-5.2.2
./configure --prefix=/home/${USERNAME}/local/gawk
make -j4
make install
export PATH=/home/${USERNAME}/local/gawk/bin:$PATH
echo "已安装gawk"

# 下载CANN-Toolkit包
cd /home/${USERNAME}/workspace
if [ -e "Ascend-cann-toolkit_8.3.RC1_linux-aarch64.run" ]; then
    file_size=$(ls -l "Ascend-cann-toolkit_8.3.RC1_linux-aarch64.run" | awk '{print $5}')
    full_size=1785287451
    if [ $file_size -lt $full_size ]; then
        echo "CANN包大小不正确，需要重新下载"
        wget https://ascend-cann.obs.cn-north-4.myhuaweicloud.com/CANN/community/Ascend-cann-toolkit_8.3.RC1_linux-aarch64.run -O Ascend-cann-toolkit_8.3.RC1_linux-aarch64.run
        chmod +x Ascend-cann-toolkit_8.3.RC1_linux-aarch64.run >/dev/null 2>&1
    fi
    echo "toolkit is exists, skipping the download step."
else
    echo "Start downloading toolkit package."
    wget https://ascend-cann.obs.cn-north-4.myhuaweicloud.com/CANN/community/Ascend-cann-toolkit_8.3.RC1_linux-aarch64.run -O Ascend-cann-toolkit_8.3.RC1_linux-aarch64.run
    chmod +x Ascend-cann-toolkit_8.3.RC1_linux-aarch64.run >/dev/null 2>&1
fi

# 安装CANN-Toolkit包
if [ ! -d "/home/${USERNAME}/8.3.RC1" ]; then
    # 不存在的时候安装
    ./Ascend-cann-toolkit_8.3.RC1_linux-aarch64.run --full --force --install-path=/home/${USERNAME}/Ascend --quiet >install.log 2>&1 &
    do_sth_pid=$(jobs -p | tail -1)
    progress "${do_sth_pid}" &
    wait "${do_sth_pid}"
    printf "\033[32m CANN包部署完成                         \033[0m\n"
else
    printf "\033[32m CANN包已部署                         \033[0m\n"
fi

# 下载CANN legacy包
if [ -e "cann-910b-opp_legacy-8.3.RC1-linux-aarch64.run" ]; then
    file_size=$(ls -l "cann-910b-opp_legacy-8.3.RC1-linux-aarch64.run" | awk '{print $5}')
    full_size=2257538929
    if [ $file_size -lt $full_size ]; then
        echo "legacy包大小不正确，需要重新下载"
        wget https://ascend-cann.obs.cn-north-4.myhuaweicloud.com/CANN/community/cann-910b-opp_legacy-8.3.RC1-linux-aarch64.run -O cann-910b-opp_legacy-8.3.RC1-linux-aarch64.run
        chmod +x cann-910b-opp_legacy-8.3.RC1-linux-aarch64.run >/dev/null 2>&1
    fi
    echo "legacy is exists, skipping the download step."
else
    echo "Start downloading legacy package."
    wget https://ascend-cann.obs.cn-north-4.myhuaweicloud.com/CANN/community/cann-910b-opp_legacy-8.3.RC1-linux-aarch64.run -O cann-910b-opp_legacy-8.3.RC1-linux-aarch64.run
    chmod +x cann-910b-opp_legacy-8.3.RC1-linux-aarch64.run >/dev/null 2>&1
fi

# 安装CANN legacy包
./cann-910b-opp_legacy-8.3.RC1-linux-aarch64.run --full --install-path=/home/${USERNAME}/Ascend --quiet >install.log 2>&1 &
printf "\033[32m legacy包已部署                         \033[0m\n"

# dos2unix gawk默认安装在/home/${USERNAME}/local路径下,可自行根据安装位置在~/.bashrc里配置以下环境变量

echo "source ${HOME}/Ascend/set_env.sh" >> ~/.bashrc
echo 'export PATH=${HOME}/local/bin:$PATH' >> ~/.bashrc
echo 'export PATH=${HOME}/local/gawk/bin:$PATH' >> ~/.bashrc
source ~/.bashrc




echo "source /usr/local/Ascend/set_env.sh" >> ~/.bashrc
echo 'export PATH=/usr/local/bin:$PATH' >> ~/.bashrc
echo 'export PATH=/usr/local/gawk/bin:$PATH' >> ~/.bashrc
source ~/.bashrc


wget https://obs-9be7.obs.cn-east-2.myhuaweicloud.com/resource/gitcode/init_env.sh
  115  ll
  116  cat init_env.sh
  117  wget https://obs-9be7.obs.cn-east-2.myhuaweicloud.com/resource/gitcode/dos2unix-7.4.4.tar.gz
  118      tar xf dos2unix-7.4.4.tar.gz
  119  ll
  120  cd dos2unix-7.4.4
  121  sed -i 's/-DENABLE_NLS //g' Makefile
  122  sed -i '/po\//d' Makefile
  123  make -j4
  124  make install
  125  dos2unix --version
  126  cd ../
  127  apt-get install gawk
  128  wget https://obs-9be7.obs.cn-east-2.myhuaweicloud.com/resource/gitcode/gawk-5.2.2.tar.gz
  129      tar xf gawk-5.2.2.tar.gz
  130  cd gawk-5.2.2/
  131  ./configure --prefix=/usr/local/gawk
  132  make -j4
  133  make install
  134  gawk --version
  135  cd ../
  136  wget https://ascend-cann.obs.cn-north-4.myhuaweicloud.com/CANN/community/Ascend-cann-toolkit_8.3.RC1_linux-aarch64.run -O Ascend-cann-toolkit_8.3.RC1_linux-aarch64.run
  137          chmod +x Ascend-cann-toolkit_8.3.RC1_linux-aarch64.run
  138  ./Ascend-cann-toolkit_8.3.RC1_linux-aarch64.run --full --force
  139  source /usr/local/Ascend/set_env.sh
  140  wget https://ascend-cann.obs.cn-north-4.myhuaweicloud.com/CANN/community/cann-910b-opp_legacy-8.3.RC1-linux-aarch64.run -O cann-910b-opp_legacy-8.3.RC1-linux-aarch64.run
  141      chmod +x cann-910b-opp_legacy-8.3.RC1-linux-aarch64.run
  142  ./cann-910b-opp_legacy-8.3.RC1-linux-aarch64.run --full
  143  ll
  144  echo "source /usr/local/Ascend/set_env.sh" >> ~/.bashrc
  145  echo 'export PATH=/usr/local/bin:$PATH' >> ~/.bashrc
  146  echo 'export PATH=/usr/local/gawk/bin:$PATH' >> ~/.bashrc
  147  source ~/.bashrc
  148  git clone https://gitcode.com/cann/ops-math.git
  149  cd ops-math
  150  pip3 install -r requirements.txt
  151  bash build.sh --pkg --soc=ascend910b --ops=abs
  152  python
  153  cd ../
  154  ll
  155  wget https://wget https://obs-9be7.obs.cn-east-2.myhuaweicloud.com/AscendC/ResourceDependent/cmake-3.28.3-linux-aarch64.tar.gz
  156  wget https://obs-9be7.obs.cn-east-2.myhuaweicloud.com/AscendC/ResourceDependent/cmake-3.28.3-linux-aarch64.tar.gz
  157      tar xf cmake-3.28.3-linux-aarch64.tar.gz
  158  cd cmake-3.28.3-linux-aarch64/
  159  https://obs-9be7.obs.cn-east-2.myhuaweicloud.com/AscendC/ResourceDependent/cmake-3.28.3-linux-aarch64.tar.gz
  160  mkdir -p /usr/local/cmake
  161  tar -zxvf cmake-3.28.3-linux-aarch64.tar.gz -C /usr/local/cmake --strip-components 1
  162  cd ../
  163  tar -zxvf cmake-3.28.3-linux-aarch64.tar.gz -C /usr/local/cmake --strip-components 1
  164  export PATH=/usr/local/cmake/bin:$PATH
  165  cmake --version
  166  vim ~/.bashrc
  167  source ~/.bashrc
  168  cd ops-math/
  201  bash build.sh --pkg --soc=ascend910b --ops=abs
  202  ./build_out/cann-ops-math-custom_linux-aarch64.run
  203  bash build.sh --run_example abs eager cust --vendor_name=custom
  204  ll
source /usr/local/Ascend/set_env.sh
export PATH=/usr/local/bin:$PATH
export PATH=/usr/local/gawk/bin:$PATH
export PATH=/usr/local/cmake/bin:$PATH

